package edu.api.math_api;

import java.util.Random;

public class Demo1 {

    public static void main(String[] args) {

        System.out.println("Math.PI = " + Math.PI);
        System.out.println("Math.E = " + Math.E);
        int a = -100;
        double b = -120.2;
        //获取绝对值
        System.out.println("Math.abs(a) = " + Math.abs(a));
        System.out.println("Math.abs(b) = " + Math.abs(b));
        //获取二者之间的最大值或最小值
        double max = Math.max(a, b);
        System.out.println("max = " + max);
        double min = Math.min(a, b);
        System.out.println("min = " + min);
        //求整运算
        System.out.println("Math.ceil(b) = " + Math.ceil(b));   //向下取整
        System.out.println("Math.floor(b) = " + Math.floor(b));   //向上取整
        System.out.println("Math.round(b) = " + Math.round(b));   //四舍五入
        System.out.println("Math.rint(b) = " + Math.rint(b));     //返回最接近的整数值，如果正好两端都有，取偶数

        //指数运算
        System.out.println("Math.exp(2) = " + Math.exp(2));  //e的2次幂
        System.out.println("Math.pow(3,4) = " + Math.pow(3, 4));  //3的4次方
        System.out.println("Math.sqrt(16) = " + Math.sqrt(16));   //平方根
        System.out.println("Math.cbrt(27) = " + Math.cbrt(27));   //次方根
        System.out.println("Math.log(2) = " + Math.log(2));       //2的自然对数

        //生成随机数
        double v = Math.random();   //[0,1)
        System.out.println("v = " + v);
        double v1 = Math.random() * 10;
        System.out.println("v1 = " + v1);  //[0,10)

        Random random = new Random();
        int i = random.nextInt();   //int范围内随机返回
        System.out.println("i = " + i);
        int i1 = random.nextInt(20);//指定随机范围
        System.out.println("i1 = " + i1);


    }

}
